/**
 * @copyright   2010-2017, The Titon Project
 * @license     http://opensource.org/licenses/BSD-3-Clause
 * @link        http://titon.io
 */

/**
 * Media query for minimum resolution.
 *
 * @param string $min
 */
@mixin if-min($min) {
    @media only screen and (min-width: $min) {
        @content;
    }
}

/**
 * Media query for maximum resolution.
 *
 * @param string $min
 */
@mixin if-max($max) {
    @media only screen and (max-width: $max) {
        @content;
    }
}

/**
 * Media query for between minimum and maximum resolution.
 *
 * @param string $min
 * @param string $max
 */
@mixin if-min-max($min, $max) {
    @media only screen and (min-width: $min) and (max-width: $max) {
        @content;
    }
}

/**
 * Media query for landscape orientation detection.
 */
@mixin if-landscape {
    @media only screen and (orientation: landscape) {
        @content;
    }
}

/**
 * Media query for portrait orientation detection.
 */
@mixin if-portrait {
    @media only screen and (orientation: portrait) {
        @content;
    }
}

/**
 * Media query for retina / HD displays.
 */
@mixin if-retina {
    @media only screen and (min-device-pixel-ratio: 2) {
        @content;
    }
}

/**
 * Maximum width cascading media query for the xsmall breakpoint.
 */
@mixin if-xsmall() {
    @include if-max(breakpoint-setting("xs", 2)) {
        @content;
    }
}

/**
 * Minimum width cascading media query for the small breakpoint.
 */
@mixin if-small() {
    @include if-min(breakpoint-setting("sm", 1)) {
        @content;
    }
}

/**
 * Minimum width cascading media query for the medium breakpoint.
 */
@mixin if-medium() {
    @include if-min(breakpoint-setting("md", 1)) {
        @content;
    }
}

/**
 * Minimum width cascading media query for the large breakpoint.
 */
@mixin if-large() {
    @include if-min(breakpoint-setting("lg", 1)) {
        @content;
    }
}

/**
 * Minimum width cascading media query for the xlarge breakpoint.
 */
@mixin if-xlarge() {
    @include if-min(breakpoint-setting("xl", 1)) {
        @content;
    }
}

/**
 * Generate either a `min-width`, `max-width`, or a combination of both for a range of breakpoints.
 *
 * @param list $range
 */
@mixin in-range($range) {
    @if type-of($range) != "list" {
        @warn "in-range() requires a list with a min and max value.";
    }

    $min: nth($range, 1);
    $max: nth($range, 2);

    @if $min and $max {
        @include if-min-max($min, $max) {
            @content;
        }

    } @else if $min {
        @include if-min($min) {
            @content;
        }

    } @else if $max {
        @include if-max($max) {
            @content;
        }
    }
}

/**
 * A media query block that includes styles between a range of two xsmall breakpoints.
 */
@mixin in-xsmall {
    @include in-range(breakpoint-setting("xs")) {
        @content;
    }
}

/**
 * A media query block that includes styles between a range of two small breakpoints.
 */
@mixin in-small {
    @include in-range(breakpoint-setting("sm")) {
        @content;
    }
}

/**
 * A media query block that includes styles between a range of two medium breakpoints.
 */
@mixin in-medium {
    @include in-range(breakpoint-setting("md")) {
        @content;
    }
}

/**
 * A media query block that includes styles between a range of two large breakpoints.
 */
@mixin in-large {
    @include in-range(breakpoint-setting("lg")) {
        @content;
    }
}

/**
 * A media query block that includes styles between a range of two xlarge breakpoints.
 */
@mixin in-xlarge {
    @include in-range(breakpoint-setting("xl")) {
        @content;
    }
}
